#import <Foundation/Foundation.h>
#import <objc/runtime.h>

#import "FWDotView.h"


static CGFloat const pi = 3.14159;


@implementation FWDotView

@synthesize color;


// ******************************************************************************************
#pragma mark -
#pragma mark Initialisation and object management

- (id)initWithFrame:(CGRect)frame
{
    if ((self = [super initWithFrame:frame])) {
    }
    
    return self;
}

- (void)dealloc
{
    [color release];
    
    [super dealloc];
}


// ******************************************************************************************
#pragma mark -
#pragma mark Drawing

- (void)drawGloss:(CGRect)rect
{
    NSBundle* bundle = [NSBundle bundleForClass:[self class]];
    NSString* path = [bundle pathForResource:(rect.size.width >= 16) ? @"gloss18" : @"gloss9"
                                      ofType:@"png"];
    UIImage* gloss = [UIImage imageWithContentsOfFile:path];
    [gloss drawInRect:rect];
}

- (void)drawRect:(CGRect)rect withGloss:(BOOL)gloss
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [color set];
    CGContextFillEllipseInRect(ctx, rect);

    if (gloss)
        [self drawGloss:rect];
}

- (void)drawRect:(CGRect) rect
{
    [self drawRect:rect withGloss:YES];
}

@end
